#!/usr/bin/python
# -*- coding: utf-8 -*-

'''
Introduction to Programming in Java - An Interdisciplinary Approach

All book programs ported to Python by
Scott C. King (revisionx at {gee}ma1l <dot> c0m).

All program examples pass Pylint with a perfect 10.00 score.
Pylint:  http://www.pylint.org/


Program 1.5.3 - Averaging a stream of numbers (one number per line)

Syntax:
python average.py
(Press CTRL-D when done, or pipe in input as in the book examples)


Notes:
sys is a required import here in order to use stdin.
https://docs.python.org/2/tutorial/stdlib.html

Division updated in PEP 238 is better suited for this task, which is
imported using the __future__ module.

https://www.python.org/dev/peps/pep-0238
https://docs.python.org/2.7/library/__future__.html
'''

from __future__ import division
import sys


def main():
    ''' Average a stream of numbers from user input using stdin '''

    total = 0
    count = 0

    while True:
        line = sys.stdin.readline()
        if line:
            line = float(line.strip())
            total += line
            count += 1
        else:
            break

    print 'Total: {}'.format(total)
    print 'Average: {:.2f}'.format(total/count)


if __name__ == '__main__':
    main()
